<template>
  <a-modal :maskClosable="false"
    :title="title"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">

    <a-spin :spinning="confirmLoading">
      <a-form-model ref="form" v-bind="layout" :model="model" :rules="validatorRules">
        <a-form-model-item label="监控编码">
          {{ model.monitorCode }}
        </a-form-model-item>
        <a-form-model-item label="处理结果">
          <a-select v-model='model.status' placeholder='请选择处理结果'>
            <a-select-option value='1'>处理中</a-select-option>
            <a-select-option value='2'>处理完成</a-select-option>
            <a-select-option value='3'>不需处理</a-select-option>
          </a-select>
        </a-form-model-item>
        <a-form-model-item label="处理结果" required prop="resultContent">
          <a-input type="textarea" style="height: 80px" placeholder="请输入处理结果" v-model="model.resultContent" />
        </a-form-model-item>
        <a-form-model-item label="处理时间" prop="handleTime">
          <a-date-picker showTime format="YYYY-MM-DD HH:mm:ss" valueFormat="YYYY-MM-DD HH:mm:ss" v-model="model.handleTime" />
        </a-form-model-item>
      </a-form-model>
    </a-spin>
  </a-modal>
</template>

<script>
import { httpAction, putAction, getAction, postAction } from '@/api/manage'

export default {
  name: 'hMonitorEventHandleResultModal',
  data() {
    return {
      title: '操作',
      visible: false,
      model: {
        status:"1",
        monitorCode:"",
      },
      layout: {
        labelCol: { span: 4 },
        wrapperCol: { span: 14 }
      },
      confirmLoading: false,
      validatorRules: {
        resultContent: [{ required: true, message: '请输入处理结果!' }],
        handleTime: [{ required: true, message: '请选择处理时间!' }],
      },
      url: {
        add: '/patient/monitor/record/result',
      }
    }
  },
  created() {
    this.modelDefault = JSON.parse(JSON.stringify(this.model))
  },
  methods: {
    edit(record) {
      this.model.monitorCode=record.monitorCode;
      this.visible = true
    },
    close() {
      this.$refs.form.clearValidate()
      this.$emit('close')
      this.visible = false
    },
    handleOk() {
      const that = this
      // 触发表单验证
      this.$refs.form.validate(valid => {
        if (valid) {
          that.confirmLoading = true
          let httpurl = ''
          let method = ''
          if (!this.model.id) {
            httpurl += this.url.add
            method = 'post'
          } else {
            httpurl += this.url.edit
            method = 'put'
          }
          httpAction(httpurl, this.model, method).then((res) => {
            if (res.success) {
              that.$message.success(res.message)
              that.$emit('ok')
            } else {
              that.$message.warning(res.message)
            }
          }).finally(() => {
            that.confirmLoading = false
            that.close()
          })
        } else {
          return false
        }
      })
    },
    handleCancel() {
      this.close()
    }

  }
}
</script>

<style scoped>

</style>